package main

import (
	xstream "gitee.com/sqxwww/xexcelize/stream"
	"github.com/360EntSecGroup-Skylar/excelize/v2"
)

const (
	rowNum = 1e5 //导出行数
	colNum = 10  //导出列数
)

func main() {
	file := excelize.NewFile()
	sw, err := file.NewStreamWriter("Sheet1")
	if err != nil {
		panic(err)
	}
	//利用excelize原生流创建自定义流
	mySw := xstream.NewMyStreamWriter(sw)
	//创建下划线样式
	underline, err := file.NewStyle(`{"font":{"color":"#1265BE","underline":"single"}}`)
	for rowID := 1; rowID <= rowNum; rowID++ {
		row := make([]interface{}, colNum)
		for colID := 0; colID < colNum; colID++ {
			//创建单元格实例，样式为下划线，公式为HYPERLINK
			row[colID] = xstream.MyCell{
				StyleID: underline,
				Formula: `HYPERLINK("https://www.baidu.com","度娘")`,
			}
		}
		cell, _ := excelize.CoordinatesToCellName(1, rowID)
		//使用自定义流按行写入
		if err = mySw.SetRow(cell, row); err != nil {
			panic(err)
		}
	}
	if err = mySw.Flush(); err != nil {
		panic(err)
	}
	file.SaveAs("example_url.xlsx")
}
